import classNames from 'classnames'

function makeCard(that){

    const {card_list, selected_list} = that.state

    return card_list.map((item, index)=>{

        const selected_id_list = selected_list.map(d=>d.id)
        const choosed = selected_id_list.indexOf(item.id) > -1
        const icon_cls = choosed ? "icon-duihao" : "icon-yuanquan"
        const is_valid = item.is_valid === 1
        const cell_cls = is_valid ? "" : "disabled"

        return (
            <div className={"cell lux-pl60 lux-pr60 lux-pb32 lux-pt32 " + cell_cls}
                 key={`card${index}`}>
                {
                    is_valid
                    ? <div className="icon lux-w50" onClick={that.pick(item.id)}>
                        <i className={classNames("iconfont", icon_cls)}/>
                      </div>
                    : <div className="icon lux-w50"></div>
                }
                <div className="logo lux-w130">
                    <img className="lux-w80 lux-h80" src={item.img} />
                </div>
                <div className="name lux-w124">
                    <p>{item.name}</p>
                </div>
                <div className="info">
                    <div className="row">
                        <p>参考价：<span className="price-red">{item.price}</span>元</p>
                    </div>
                    <div className="row lux-mt5">
                        <p>预计送达时间：{item.time}天</p>
                    </div>
                </div>
            </div>
        )
    })
}



export default function (that) {
    return (
        <div className={classNames("ExpressCard", that.props.className)} >
            <div className="ExpressCard-wrapper">
                {makeCard(that)}
            </div>
        </div>
    )
}